#ifdef _WIN32
#include<windows.h> // needed for windows systems
#endif
#include<GL/glut.h>
#include<GL/gl.h>
#include<GL/glu.h>
#include "reshape.h"

/* world_wintypical dimensions of the world window
 * These dimensions MUST be set for keepWholeWindow() to work */
float world_win_x, world_win_y, world_win_z, world_win_width, world_win_height, world_win_depth;

void keepWholeWindow(GLsizei w, GLsizei h)
{
    /* keeps the original window in view, maintaining aspect ratio, 
     * but allows it to be wider or taller than defined */
    float world_win_aspect_ratio,
          aspect_ratio,
          current_x,
          current_y,
          current_width,
          current_height;

    glViewport(0, 0, w, h);
    if (world_win_height && world_win_width && h && w)
    {
        world_win_aspect_ratio = world_win_width / world_win_height;
        aspect_ratio = (float)w / h;
    }
    /* if either height or width is zero bail out */
    else return;

    glMatrixMode (GL_PROJECTION);
    glLoadIdentity();
    if (aspect_ratio >= world_win_aspect_ratio)
    {
       current_x = world_win_x * aspect_ratio / world_win_aspect_ratio;
       current_y = world_win_y;
       current_width = world_win_width * aspect_ratio / world_win_aspect_ratio;
       current_height = world_win_height;
    }
    else
    {
       current_x = world_win_x;
       current_y = world_win_y * world_win_aspect_ratio / aspect_ratio;
       current_width = world_win_width;
       current_height = world_win_height * world_win_aspect_ratio / aspect_ratio;
    }
//    glOrtho(current_x, current_x + current_width,
//            current_y, current_y + current_height,
//            -1, 1);
//            
//gluPerspective(45, current_width/current_height, 1, 2000);
      glFrustum(current_x, current_x + current_width,
                current_y, current_y + current_height,
                world_win_z, world_win_z + world_win_depth);

}
